#!usr/bin/node

const Koa = require('koa');

const app = new Koa();

app.use(async (ctx,next) => {
  if(ctx.method === 'GET' && ctx.path === '/api/authors/') {
    console.log('得到漫画书作者列表');
    ctx.body = 'get authors list ok';
  }
  if(ctx.method === 'GET' && /\/api\/authors\/\w/.test(ctx.path) ) {
    console.log('按作者名称查询');
    ctx.body = 'get authors by name ok';
  }
  if(ctx.method === 'POST' && ctx.path === '/api/authors/') {
    console.log('添加新的漫画书作者');
    ctx.body = 'insert ok';
  }
  if(ctx.method === 'PUT' && /\/api\/authors\/(\d)+$/.test(ctx.path)) {
    console.log('修改某ID的漫画书作者信息');
    ctx.body = 'update ok';
  }
  if(ctx.method === 'DELETE' && /\api\/authors\/(\d)+$/.test(ctx.path)) {
    console.log('删除某ID的漫画书作者信息');
    ctx.body = 'delete ok';
  }
});

app.listen(8080);
